#ifndef ADMINMENU_H
#define ADMINMENU_H

#include <QMainWindow>
#include <QSqlDatabase>
#include <QMessageBox>
#include <QSqlQueryModel>
#include <QMouseEvent>
#include "User.h"
#include "DatabaseManager.h"

#define Admin_Debug 1

namespace Ui {
class AdminMenu;
}

class AdminMenu : public QMainWindow
{
    Q_OBJECT

public:
    explicit AdminMenu(QWidget *parent = nullptr);
    explicit AdminMenu(User user = User(),QWidget* parent = nullptr);
    ~AdminMenu();

    void initMenu(void);
    void initUserManagePageMenu(void);
    void initLogManagePageMenu(void);
protected:
    void mouseReleaseEvent(QMouseEvent *event) override;

private slots:
    /*========================<用户管理界面的按钮槽函数>========================*/
    void m_on_userManage_tv_userInfoList_clicked(const QModelIndex& index);
    void m_on_userManage_btn_add_clicked(void);
    void m_on_userManage_btn_delete_clicked(void);
    void m_on_userManage_btn_update_clicked(void);
    void m_on_userManage_btn_find_clicked(void);
    void m_on_userManage_tbtn_permissionBitsChose_clicked(void);
    /*========================<日志管理界面的按钮槽函数>========================*/
    void m_on_logManage_tv_logInfoList_clicked(const QModelIndex &index);
private:
    Ui::AdminMenu *ui;

    DatabaseManager* m_DBManager;

    QSqlQueryModel* m_userSqlQueryModel;
    QSqlQueryModel* m_logSqlQueryModel;

    bool m_tv_userInfoListSelectflag;
    int m_tv_userInfoListSelectUserId;

    User m_operatorUserInfo;
};
/*==========================<自定义QSqlQueryModel>==========================*/
//自定义QSqlQueryModel，为了将字段中的毫秒时间戳转换成yyyy-MM-dd HH:mm:ss.zzz直接显示
class LogEntryManagerSqlQueryModel:public QSqlQueryModel
{
public:
    LogEntryManagerSqlQueryModel(QObject* parent = nullptr);
    QVariant data(const QModelIndex& index,int role = Qt::DisplayRole)const override;
};

#endif // ADMINMENU_H
